package com.stylefeng.guns.modular.merchant.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stylefeng.guns.common.exception.BizExceptionEnum;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.modular.merchant.dao.MerchantDao;
import com.stylefeng.guns.modular.merchant.service.MerchantService;
import com.stylefeng.guns.modular.merchant.transfer.MerchantDto;

/**
 * 商户管理控制器
 *
 * @author Mister.3
 * @Date 2017-12-04 21:11:36
 */
@Controller
@RequestMapping("/merchant")
public class MerchantController extends BaseController {

    private String PREFIX = "/merchant/merchant/";

    @Resource
    private MerchantDao merchantDao;
    @Resource
    private MerchantService merchantService;
    /**
     * 跳转到审批管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "merchant.html";
    }


    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        List<Map<String, Object>> list = this.merchantDao.list(condition);
        return list;
    }
    /**
     * 商户添加
     * @return
     */
    @RequestMapping(value = "/merchant_add_pre")
    public String merchantAddPre(String condition) {
        return PREFIX + "merchant_add.html";
    }
    
    /**
     * 商户添加
     * @return
     */
    @RequestMapping(value = "/merchant_add")
    @ResponseBody
    public Object merchantAdd(@Valid MerchantDto merchantDto, BindingResult result) {
    	
    	if (result.hasErrors()) {
            throw new GunsException(BizExceptionEnum.REQUEST_NULL);
        }
    	merchantService.insertMerchant(merchantDto);
        return SUCCESS_TIP;
    }
    
}
